Skip to content

add: option to return non-zero if files are changed#532

Open
chadrik wants to merge 2 commits into
hukkin:masterfrom
chadrik:error-on-fix
Open

add: option to return non-zero if files are changed#532
chadrik wants to merge 2 commits into
hukkin:masterfrom
chadrik:error-on-fix

Conversation

@chadrik

@chadrik chadrik commented Aug 16, 2025

Copy link
Copy Markdown

Fixes #531

@cdombrova-scanlinevfx

Copy link
Copy Markdown

It would be great if someone could look at this!

@nrusch

nrusch commented Feb 9, 2026

Copy link
Copy Markdown

I'd be very interested in this feature as well.

@KyleKing KyleKing left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see this being useful in similar scenarios as to why ruff adopted it, but I can't think of other tools that implement this pattern.

Also, I'm not sure if hukkin will have time to review or would approve, so take my feedback with a grain of salt!

Comment thread tests/test_cli.py
file_path_1.write_text(UNFORMATTED_MARKDOWN)
file_path_2.write_text(UNFORMATTED_MARKDOWN)
file_path_3.write_text(UNFORMATTED_MARKDOWN)
assert run((str(tmp_path),), "--exit-non-zero-on-format") == 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there might be an error in this test if I understand it correctly:

Suggested change
assert run((str(tmp_path),), "--exit-non-zero-on-format") == 1
assert run((str(tmp_path), "--exit-non-zero-on-format")) == 0

Comment thread src/mdformat/_cli.py
"--exit-non-zero-on-format",
action="store_true",
help="return non-zero if files are modified",
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new option should be mutually exclusive with --check (and maybe better document that both are CLI only because it doesn't make sense to configure these permanently in toml)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide an option to apply changes and exit non-zero if changes were made

4 participants